package main;

import java.awt.Dimension;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JFileChooser;
import model.DataSource;
import model.DataTable;
import view.GraphManager;


/**
 * The controller for our visualization project
 * 
 * @author David Spruill
 *         Code for file reading written by Professor Duvall
 *         edited by Wynne Lok
 * 
 */
public final class Main {
    // constants
    private static final Dimension SIZE = new Dimension(800, 800);
    private static final JFileChooser OUR_CHOOSER = new JFileChooser(System.getProperties()
           .getProperty("user.dir"));
    private static final int INPUT_OFFSET = 150;
    private GraphManager myGraphs;
    private File myInputFile;
    private Controller myController;
    private DataSource mySource;

    private Main () {
    }

    /**
     * Start of the program.
     * 
     * @param args
     *        command-line arguments
     */
    public static void main (String[] args) {

        Main main = new Main();

        main.myInputFile = null;
        int response = OUR_CHOOSER.showOpenDialog(null);
        if (response == JFileChooser.APPROVE_OPTION) {
            main.myInputFile = OUR_CHOOSER.getSelectedFile();
        }
        main.mySource = new DataTable();
        main.mySource.loadDataFromFile(main.myInputFile);

        List<String> dataColumns = main.mySource.getColumnNames();
        List<String> inputData = main.mySource.getColumn(dataColumns.get(1));
        List<Object> data = new LinkedList<Object>();
        data.add(dataColumns.get(1));
        for (String number : inputData) {
            data.add(Integer.parseInt(number));
        }
        inputData = main.mySource.getColumn(dataColumns.get(1));
        List<Object> xdata = new LinkedList<Object>();
        for (String number : inputData) {
            xdata.add(Integer.parseInt(number));
        }

        main.myGraphs = new GraphManager(SIZE, INPUT_OFFSET, data);
        main.myController = new Controller(main.myGraphs);
        // main.myGraphs.usersSelect(SIZE);
        // main.myGraphs.setData();
        // main.myController.giveController(main.myGraphs);
        main.myGraphs.setVisible(true);
    }

    /**
     * Asks the user what data file to read in.
     */

}
